<template>
  <div class="transQuery_main">
    <a-table
      size="middle"
      :scroll="{ y: '70vh' }"
      :columns="columns"
      :dataSource="list"
      :pagination="false"
      :rowKey="record => record.id"
    >
      <span slot="startDate" slot-scope="record">{{record.startDate | dateFilter}}</span>
      <!-- <span slot="amount" slot-scope="record">{{(record.amount/100).toFixed(2)}}</span> -->
      <span slot="amount" slot-scope="record">{{record.amount}}</span>
      <span slot="deductDate" slot-scope="record">每月{{record.deductDate}}日</span>
      <span slot="action" slot-scope="record">
        <span @click="goDetail(record.id)" style="color:#1890ff;">详细</span>
      </span>
    </a-table>
    <a-pagination
      @change="onPageChange"
      :current="pagination.current"
      :total="pagination.total"
      :pageSize="query.pageSize"
      style="margin-top: 20px"
    />
  </div>
</template>

<script>
import AForm from "ant-design-vue/es/form/Form";
import ATabs from "ant-design-vue/es/tabs";
import AFormItem from "ant-design-vue/es/form/FormItem";
import AInput from "ant-design-vue/es/input/Input";
import AIcon from "ant-design-vue/es/icon";
import AInputGroup from "ant-design-vue/es/input/Group";
import AButton from "ant-design-vue/es/button/button";
import ACol from "ant-design-vue/es/grid/Col";
import ARow from "ant-design-vue/es/grid/Row";
import ACheckbox from "ant-design-vue/es/checkbox/Checkbox";
import AAlert from "ant-design-vue/es/alert/index";
import moment from "moment";
import api from "@/common/api";
const ATabPane = ATabs.TabPane;

const columns = [
  { title: "创建日期", dataIndex: "ctime", width: "20%", align: "center" },
  {
    title: "扣款总金额(元)",
    scopedSlots: { customRender: "amount" },
    width: "20%",
    align: "center"
  },
  {
    title: "扣款日期",
    scopedSlots: { customRender: "deductDate" },
    width: "20%",
    align: "center"
  },
  {
    title: "扣款开始日期",
    scopedSlots: { customRender: "startDate" },
    width: "25%",
    align: "center"
  },
  {
    title: "操作",
    scopedSlots: { customRender: "action" },
    width: "15%",
    align: "center"
  }
];

export default {
  name: "payInstalmentsQuery",
  components: {
    AAlert,
    ACheckbox,
    ACol,
    ARow,
    AButton,
    AInputGroup,
    AIcon,
    AInput,
    AFormItem,
    ATabPane,
    ATabs,
    AForm
  },

  data() {
    return {
      today: new Date(),
      columns,
      isClear: false,
      momentDate: moment(new Date()),
      excelurl: "",
      query: {
        page: 1,
        pageSize: 10,
        data: {}
      },
      pagination: { current: null, total: null },
      visible: false,
      form: this.$form.createForm(this),
      error: "",
      loginpwd: "",
      loginpwd2: "",
      login: false,
      list: [],
      count: null,
      loading: false,
      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 14, offset: 1 },
          md: { span: 14, offset: 1 }
        }
      }
    };
  },
  watch: {},
  filters: {
    timeFilter: function(value) {
      if (value) {
        let year = value.substring(0, 2);
        let mouth = value.substring(2, 4);
        let day = value.substring(4, 6);
        return year + ":" + mouth + ":" + day;
      }
    },
    dateFilter: function(value) {
      if (value) {
        let year = value.substring(0, 4);
        let mouth = value.substring(4, 6);
        let day = value.substring(6, 8);
        return year + "-" + mouth + "-" + day;
      }
    }
  },
  computed: {},
  created() {},
  mounted() {
    this.handleSearch();
  },
  methods: {
    moment,
    onPageChange: function(page, pageSize) {
      console.info(page, pageSize);
      this.query.page = page;
      this.query.pageSize = pageSize;
      this.handleSearch();
    },
    onChange(dates, dateStrings) {
      this.query.data.transDate = dateStrings;
      console.info(this.query.data.transDate);
    },

    handleSearch() {
      this.loading = true;
      console.info(this.query);
      api.payInstalmentsQuery(
        this.query,
        res => {
          console.info(res);
          if (res.code == "OK") {
            this.loading = false;
            this.list = res.list;
            // this.list.forEach(function(item) {
            //   item.amount = item.amount.toFixed(2);
            // });
            this.pagination.current = res.current;
            this.pagination.total = res.total;
          } else {
            this.loading = false;
            // this.$message.info(res.message)
            this.list = [];
            this.pagination.current = 1;
            this.pagination.total = 1;
            return false;
          }
        },
        err => {
          console.log("err", err);
          if (err) {
            this.loading = false;
          }
        }
      );
    },
    goDetail(id) {
      console.log(id);
      this.$router.push(`/marketing/payInstalmentsQueryDetail/${id}`);
    }
  }
};
</script>

<style lang="less" scoped>
span {
  cursor: pointer;
}

span {
  cursor: pointer;
}

.formGroupTitle {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
}

.ant-tabs-nav {
  float: right;
}

.amountColor {
  color: #29a576;
  font-weight: 400;
}

.amountSize {
  font-size: 20px;
  padding: 0 5px;
}

.expand {
  display: flex;
  align-items: center;
  justify-content: center;
}

.transQuery_main {
  /* padding: 30px 40px; */
  padding: 70px;
}

.button_sty {
  width: 100%;
}
</style>